/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tamnhat.webservice.ws;

import com.tamnhat.entity.SDP_CONTENT;
import com.tamnhat.entity.SEC_USER;
import com.tamnhat.ws.Constants;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

/**
 *
 * @author Administrator
 */
@WebService(serviceName = "ContentWS")
public class ContentWS {

    /**
     * Web service operation
     */
    @WebMethod(operationName = "insertContent")
    public String insertContent(@WebParam(name = "username") String username, @WebParam(name = "password") String password, @WebParam(name = "sdp_content") SDP_CONTENT sdp_content, @WebParam(name = "list_sdp_content_details") com.tamnhat.entity.SDP_CONTENT_DETAILS[] list_sdp_content_details) {
        try {
            SEC_USER sec_user = new SEC_USER();
            sec_user.setUser_name(username);
            sec_user.setPassword(password);
            if (!sec_user.checkUser().equals(Constants.SUCCESS)) {
                return sec_user.checkUser();
            }

            if(!sec_user.checkProductCodeByUserId(sdp_content.getProductIdByCode()).equals(Constants.SUCCESS)){
                return sec_user.checkProductCodeByUserId(sdp_content.getProductIdByCode());
            }
            
            if(list_sdp_content_details == null || list_sdp_content_details.length == 0){
                return Constants.NO_CONTENT_DETAIL;
            }
            
            for(int i=0;i<list_sdp_content_details.length;i++){
                if(list_sdp_content_details[i].getProduct_content_type() == null || (!list_sdp_content_details[i].getProduct_content_type().equals("text") && !list_sdp_content_details[i].getProduct_content_type().equals("wappush"))){
                    return Constants.INVALID_PRODUCT_CONTENT_TYPE;
                }
            }
            sdp_content.setListDetail(list_sdp_content_details);
            
            if(sdp_content.insert()){
                return Constants.SUCCESS;
            }
            return Constants.FAIL;            
        } catch (Exception e) {
            e.printStackTrace();
            return Constants.INTERAL_ERROR;
        }
    }
    /**
     * This is a sample web service operation
     */
}
